Skip to content

Commit b0d4dd8

Browse files
committed
[Tests] add more coverage from tc39/test262#3994
1 parent 6adae55 commit b0d4dd8

5 files changed

+177
-78
lines changed

test/Uint8Array.fromBase64.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,39 @@ module.exports = {
171171
SyntaxError
172172
);
173173

174+
// partial padding
175+
s2t['throws'](
176+
function () { method('ZXhhZg='); },
177+
SyntaxError
178+
);
179+
s2t['throws'](
180+
function () { method('ZXhhZg=', { lastChunkHandling: 'loose' }); },
181+
SyntaxError
182+
);
183+
s2t.deepEqual(method('ZXhhZg=', { lastChunkHandling: 'stop-before-partial' }), new Uint8Array([101, 120, 97]));
184+
s2t['throws'](
185+
function () { method('ZXhhZg=', { lastChunkHandling: 'strict' }); },
186+
SyntaxError
187+
);
188+
189+
// excess padding
190+
s2t['throws'](
191+
function () { method('ZXhhZg==='); },
192+
SyntaxError
193+
);
194+
s2t['throws'](
195+
function () { method('ZXhhZg===', { lastChunkHandling: 'loose' }); },
196+
SyntaxError
197+
);
198+
s2t['throws'](
199+
function () { method('ZXhhZg===', { lastChunkHandling: 'stop-before-partial' }); },
200+
SyntaxError
201+
);
202+
s2t['throws'](
203+
function () { method('ZXhhZg===', { lastChunkHandling: 'strict' }); },
204+
SyntaxError
205+
);
206+
174207
s2t.end();
175208
});
176209

@@ -194,6 +227,16 @@ module.exports = {
194227
);
195228
s2t.deepEqual(results(), []);
196229

230+
s2t['throws'](
231+
function () { method('Zg==', { alphabet: Object('base64') }); },
232+
TypeError
233+
);
234+
235+
s2t['throws'](
236+
function () { method('Zg==', { lastChunkHandling: Object('loose') }); },
237+
TypeError
238+
);
239+
197240
s2t.test('getters', { skip: !defineProperties.supportsDescriptors }, function (s3t) {
198241
var base64UrlOptions = {};
199242
var alphabetResults = s3t.intercept(base64UrlOptions, 'alphabet', { get: function () { return 'base64url'; } });
@@ -246,6 +289,7 @@ module.exports = {
246289
forEach(standardBase64Vectors, function (pair) {
247290
var arr = method(pair[0]);
248291
s2t.equal(getProto(arr), Uint8Array.prototype, 'decoding ' + pair[0]);
292+
s2t.equal(arr.buffer.byteLength, pair[1].length, 'decoding ' + pair[0]);
249293
s2t.deepEqual(arr, new Uint8Array(pair[1]), 'decoding ' + pair[0]);
250294
});
251295

@@ -303,6 +347,9 @@ module.exports = {
303347
];
304348
forEach(whitespaceKinds, function (pair) {
305349
var arr = method(pair[0]);
350+
351+
s2t.equal(arr.length, 1);
352+
s2t.equal(arr.buffer.byteLength, 1);
306353
s2t.deepEqual(arr, new Uint8Array([102]), 'ascii whitespace: ' + pair[1]);
307354
});
308355

test/Uint8Array.fromHex.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ module.exports = {
6464
'a\x0Da',
6565
'a\u00A0a', // nbsp
6666
'a\u2009a', // thin space
67-
'a\u2028a' // line separator
67+
'a\u2028a', // line separator
68+
'a' // odd length input
6869
];
6970
forEach(illegal, function (value) {
7071
st['throws'](
@@ -87,6 +88,8 @@ module.exports = {
8788
forEach(cases, function (pair) {
8889
var arr = method(pair[0]);
8990
st.equal(getProto(arr), Uint8Array.prototype, 'decoding ' + pair[0]);
91+
st.equal(arr.length, pair[1].length, 'decoding ' + pair[0]);
92+
st.equal(arr.buffer.byteLength, pair[1].length, 'decoding ' + pair[0]);
9093
st.deepEqual(arr, new Uint8Array(pair[1]), 'decoding ' + pair[0]);
9194
});
9295

@@ -95,9 +98,7 @@ module.exports = {
9598
var results = s2t.intercept(
9699
throwyToString,
97100
'toString',
98-
{
99-
value: function () { throw new EvalError('toString called'); }
100-
}
101+
{ value: function () { throw new EvalError('toString called'); } }
101102
);
102103

103104
s2t['throws'](

0 commit comments

Comments
 (0)